home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / mint / duftp / init.c < prev    next >
C/C++ Source or Header  |  1995-06-17  |  8KB  |  242 lines

  1. /*
  2.     DUFTP
  3. */
  4.  
  5. // Initialisation code
  6.  
  7. #include <DULIB.H>
  8. #include <SIGNAL.H>
  9. #include <SETJMP.H>
  10. #include "globals.h"
  11. #include "duftp_n.h"
  12. #include "dispatch.h"
  13. #include "ftp.h"
  14. #include "servers.h"
  15. #include "gui2ftp.h"
  16. #include "dip.h"
  17. #include "local_fs.h"
  18.  
  19. // Debug code
  20.  
  21. void illegal_sig(int a)
  22. {
  23.     form_alert(1,"[1][ Illegal instruction. | Please use QUIT to exit correctly. ][ OK ]");
  24.     signal(a,illegal_sig);
  25.     longjmp(recover_main,1);
  26. }
  27.  
  28. void berr_sig(int a)
  29. {
  30.     form_alert(1,"[1][ Bus Error. | Please use QUIT to exit correctly. ][ OK ]");
  31.     signal(a, berr_sig);
  32.     longjmp(recover_main,1);
  33. }
  34.  
  35. void int_sig_handler(int a)
  36. {
  37.  
  38.     form_alert(1,"[1][ Please use QUIT to exit correctly. ][ OK ]");
  39.     signal(a,int_sig_handler);
  40.     longjmp(recover_main,1);
  41. }
  42.  
  43. short scan_code_reporter(void)
  44. {
  45.     char al[200];
  46.     sprintf(al,"[1][ Scan code = 0x%x       ][ ok ]", kc_key);
  47.     form_alert(1,al);
  48.     return TRUE;
  49. }
  50.  
  51. char version_string[100];
  52.  
  53. void initialise(void)
  54. {
  55.     char al[FMSIZE],*rsc1,*rsc2;
  56.     short d,inv[512];
  57.     
  58.     original_SIGCHLD=signal(SIGCHLD,SIG_IGN);
  59.  
  60.     initial_dir=(char*)malloc(sizeof(char)*FMSIZE);
  61.  
  62.     getcwd(al,FMSIZE);
  63.     
  64.     if (!strncmp("/dev",al,4))
  65.     {
  66.         if ((al[5]=='u')&&(al[6]=='/'))
  67.             sprintf(initial_dir,"u:%s",al+6);
  68.         else
  69.             sprintf(initial_dir,"u:%s",al+4);
  70.     }else{
  71.         sprintf(initial_dir,"%s",al);
  72.     }
  73.     
  74.     load_servers();
  75.     
  76. // DULIB GUI INITIALISATION
  77.     enviroment_initialise();
  78.     
  79.     if ((AESversion>=3)&&(AESversion_m>=6))    // Have we got a new enough AES to use CICONS?
  80.     {
  81.         rsc1="DUFTP_N.RSC";
  82.         rsc2="duftp_n.rsc";
  83.     }else{
  84.         rsc1="DUFTP_O.RSC";
  85.         rsc2="duftp_o.rsc";
  86.     }
  87.     
  88.     d=rsrc_load(rsc1);                        // Load resources
  89.     if (!d)
  90.     {
  91.         d=rsrc_load(rsc2);            // Load resources (minixFS support, check both cases)
  92.         if (!d)
  93.         {
  94.             sprintf(al,"[1][ Cann't load resource ? | File: '%s'. ][ EXIT ]",rsc1);
  95.             form_alert(1,al);
  96.             exit(1);
  97.         }
  98.     }
  99.  
  100.     install_menu(Mainmenu);        // Install menu
  101.     
  102. // Configure for mono displays if we need to
  103.     vq_extnd(x_handle,0,inv);
  104.     if (inv[13]<16)
  105.     {
  106.         rsrc_form2mono(Mainwindow, 0);
  107.         rsrc_form2mono(Hosts, 0);
  108.         rsrc_form2mono(Open_new, 0);
  109.         rsrc_form2mono(Dip_dialing,0);
  110.         rsrc_form2mono(Dip_connected,0);
  111.         rsrc_form2mono(Ftp_progress,0);
  112.         rsrc_form2mono(About,1);
  113.     }
  114.     
  115. // Set up the events
  116.     Set_object_event(Mainmenu, File_quit, mev_QUIT);
  117.     Set_object_callback(Mainmenu, Dial_connect, &dip_dialup);
  118.     Set_object_callback(Mainmenu, Dial_disconnect, &dip_hangup);
  119.     Set_object_callback(Mainmenu, File_save_bm, &save_servers);
  120.     Set_object_callback(Mainmenu, Mftp_open, &dispatcher);
  121.     Set_object_callback(Mainmenu, Mftp_close, &close_current_session);
  122.     Set_object_callback(Mainmenu, Help, &dialog_help);
  123.     Set_object_event(Mainmenu, Mftp_stop, mev_STOPTRANSFER);
  124.     Set_object_callback(Mainwindow, This_server, &popup_select_server);
  125.     Set_object_callback(Mainwindow, Open_server, &open_selected_server);
  126.     Set_object_callback(Mainwindow, Close_server, &close_current_session);
  127.     Set_object_callback(Mainwindow, Open_new_server, &dispatcher);
  128.     Set_object_callback(Mainwindow, Add_new_bookmark, &add_current_server);
  129.     Set_object_event(Ftp_progress, Pftp_stop, mev_STOPTRANSFER);
  130.     Set_scroll_list(Hosts, Listhosts, mev_SELBOOKMARK, server_name_list, server_count, 5);
  131.     Set_object_callback(Hosts, Save_servers, &save_servers);
  132.     Set_object_callback(Hosts, New_server, &add_new_server);
  133.     Set_object_callback(Hosts, Delete_server, &delete_server);
  134.  
  135. // Attach a few automatic close options
  136.     Set_object_callback(Open_new, Open_new_open, &destructor);
  137.     Set_object_callback(Open_new, Open_new_cancel, &destructor);
  138.     Set_dialog_Kcallback(Open_new, &Kdestructor);        // In Open_new dialog, Return==Open FTP
  139.  
  140. // Editable text fields in the open new server dialog
  141.     sprintf(new_server_address,"                                         ");
  142.     sprintf(new_server_login,"anonymous                                ");
  143.     sprintf(new_server_password,"me@localhost                             ");
  144.     set_dialog_text(Open_new, Open_new_name,new_server_address);
  145.     set_dialog_text(Open_new, Open_new_login,new_server_login);
  146.     set_dialog_text(Open_new, Open_new_pass,new_server_password);
  147.     set_dialog_text(Open_new, Open_new_path,new_server_path);
  148.     Set_object_editable(Open_new, Open_new_path);
  149.     Set_object_editable(Open_new, Open_new_pass);
  150.     Set_object_editable(Open_new, Open_new_login);
  151.     Set_object_editable(Open_new, Open_new_name);
  152.     Set_dialog_Kfocus(Open_new, Open_new_name);
  153.  
  154. // Editable text fields in the Hosts dialog
  155.     set_dialog_text(Hosts, Server_name, selected_server->name);
  156.     set_dialog_text(Hosts, Ip_address, selected_server->ip_name);
  157.     set_dialog_text(Hosts, Login_name, selected_server->login);
  158.     set_dialog_text(Hosts, Login_password, selected_server->password);
  159.     set_dialog_text(Hosts, Login_path, selected_server->path);
  160.     Set_object_editable(Hosts, Login_path);
  161.     Set_object_editable(Hosts, Login_password);
  162.     Set_object_editable(Hosts, Login_name);
  163.     Set_object_editable(Hosts, Ip_address);
  164.     Set_object_editable(Hosts, Server_name);
  165.     Set_dialog_Kfocus(Hosts, Server_name);
  166.     
  167. // Setup the GEMLIST standard keyboard shortcuts.
  168.     Set_standard_keyboard();
  169.     Set_dialog_Kfocus_policy(Hosts, FOCUS_FIELD);
  170.     Set_dialog_Kfocus_policy(Open_new, FOCUS_FIELD);
  171.     Set_key_callback(0x3000, &Kdispatcher);                // ALT+B = Bookmarks
  172.     Set_key_callback(0x2100, &Kdispatcher);                // ALT+F = File transfer
  173.     Set_key_callback(0x1f13, &save_servers);            // ^S = Save Bookmarks
  174.     Set_key_callback(0x1800, &Kdispatcher);                // ALT+O = Open FTP
  175.     Set_key_callback(0x2e00, &close_current_session);    // ALT+C = Close current session
  176.  
  177. // Attatch the dialog dispatcher to menu options that open windows
  178.     Set_object_callback(Mainmenu, About_ftp, &dispatcher);
  179.     Set_object_callback(Mainmenu, Win_ftp, &dispatcher);
  180.     Set_object_callback(Mainmenu, Win_hosts, &dispatcher);
  181.  
  182. // debug stuff - setup a scan code reporter in the About Dialog
  183.     Set_dialog_Kcallback(About, &scan_code_reporter);
  184.  
  185.     initialise_ftp();
  186.  
  187. // Hook in a few signal handlers
  188. //    signal(SIGINT, int_sig_handler);    // Interupt
  189. //    signal(SIGILL, illegal_sig);        // Illegal instruction - try to catch errors
  190. //    signal(SIGBUS, berr_sig);            // Bus error - hope to catch bad pointers
  191.  
  192. // Initially, localhost is the selected server - always last entry in file:ie. first server in list
  193.     selected_server=servers;
  194.     set_dialog_text(Mainwindow, This_server, selected_server->name);
  195.  
  196. // Remote directory listing - set to empty
  197.     remote_directory=NULL;
  198.     remote_files=(char **)malloc(sizeof(char*));
  199.     file_count=0;
  200.     remote_files[0]="                          ";
  201.     Set_scroll_list(Mainwindow, Remote_fs, mev_REMOTEFILE, remote_files, 1, 11);
  202.     Set_scroll_list(Mainwindow, Local_fs, mev_LOCALFILE, remote_files, 1, 11);
  203.     Set_object_devent(Mainwindow, Remote_fs+scroll_text_area, mev_CHANGEREMOTEDIR);
  204.     set_dialog_text(Mainwindow, Remote_path, " ");
  205.  
  206. // Local directory listing
  207.     sprintf(current_local_path, "%s", initial_dir);
  208.     local_files=NULL;
  209.     local_directory=NULL;
  210.     get_local_files();
  211.     if (local_files) free(local_files);
  212.     d=file_count;
  213.     local_files=extract_filenames(local_directory);
  214.     local_file_count=file_count;
  215.     file_count=d;
  216.     Change_scroll_list(Mainwindow, Local_fs, local_files, local_file_count+1);
  217.     Set_object_devent(Mainwindow, Local_fs+scroll_text_area, mev_CHANGELOCALDIR);
  218.     set_dialog_text(Mainwindow, Local_path, current_local_path);
  219.  
  220. // Set the version date in the about dialog
  221.     sprintf(version_string, "Version date:%s time:%s",__DATE__,__TIME__);
  222.     set_dialog_text(About, Version_date, version_string);
  223.  
  224. // Hypertext help
  225.     Set_application_helpfile("DUFTP.HYP");                // The application's help file
  226.     Set_dialog_help_topic(Mainwindow,"Getting Files");    // Setup the context sensitive help system
  227.     Set_dialog_help_topic(Open_new,"FTP Connections");
  228.     Set_dialog_help_topic(Hosts,"Bookmarks");
  229.     Set_dialog_help_topic(About,"Introduction");
  230.  
  231. void reset_remote_list(void)
  232. {
  233.     file_count=0;
  234.     if (remote_files) free(remote_files);
  235.     remote_files=(char **)malloc(sizeof(char*));
  236.     file_count=0;
  237.     remote_files[0]="                          ";
  238.     Change_scroll_list(Mainwindow, Remote_fs, remote_files, 1);
  239.     set_dialog_text(Mainwindow, Remote_path, " ");
  240. }
  241.